<div class="row-fluid">
    <div class="span12">
        <div class="box paint color_11">
            <div class="title">
                <h4> <i class="icon-book"></i><span><?php echo __('Edit Team'); ?></span> </h4>
            </div>
            <div class="content">
                <?php echo $this->Form->create('Discipline', array('class' => 'form-horizontal row-fluid')); ?>
                    <?php echo $this->Form->input('id'); ?>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Discipline') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->select('_team', $teamsL, array('div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Team') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->input('team', array('div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Semester') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->input('semester', array('div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Courses') ?></label>
                        <div class="controls span7">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th><?php echo __('Name') ?></th>
                                        <th width="15%"><?php echo __('Actions') ?></th>
                                    </tr>
                                </thead>
                                <tbody id="course"> 
                                    <?php foreach ($this->request->data['Courses'] as $key => $value): ?>
                                        <tr id="<?php echo $value['id']; ?>">
                                            <td>
                                                <?php echo $value['name']; ?>
                                            </td>
                                            <td>
                                                <button class="btn success" id="<?php echo $value['id']; ?>"><i class="icon-minus"></i> Remover</button>
                                            </td>
                                        </tr>
                                        <?php
                                        $this->Js->get('#'.$value['id']);
                                        echo $this->Js->event('click', $this->Js->request(
                                            array('controller' => 'CoursesDisciplines', 'action' => 'delete', $value['id'], $this->request->data['Discipline']['id']),
                                            array(
                                                'method' => 'post',
                                                'type' => 'html',
                                                'success' => '$("#'.$value['id'].'").remove()',
                                                'async' => 'true',
                                            )
                                            ));
                                        echo $this->Js->writeBuffer();
                                        ?>

                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Course') ?></label>
                        <div class="controls span6">
                            <?php echo $this->Form->select('course', $courses, array('div' => false, 'id' => 'courseS', 'label' => false, 'class' => 'row-fluid')); ?> 
                        </div>
                        <div class="controls span1">
                            <button class="btn success" id="addCourse"><i class="icon-plus"></i> Adicionar</button>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Theoretical Workload') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->input('theoretical_workload', array('id' => 'mask-phone','type' => 'text', 'div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Practice Workload') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->input('practice_workload', array('id' => 'mask-phone','type' => 'text', 'div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-row control-group row-fluid">
                        <label class="control-label span3" for="normal-field"><?php echo __('Total Workload') ?></label>
                        <div class="controls span7">
                            <?php echo $this->Form->input('total_workload', array('id' => 'mask-phone', 'type' => 'text', 'div' => false, 'label' => false, 'class' => 'row-fluid')); ?>
                        </div>
                    </div>
                    <div class="form-actions row-fluid">
                        <div class="span7 offset3">
                            <button type="submit" class="btn btn-primary"><?php echo __('Submit') ?></button>
                        </div>
                    </div>
                <?php $this->Form->end() ?>
            </div>
        </div>
    </div>
</div>

<?php $this->Js->get('#addCourse');
    echo $this->Js->event('click', 
        'if($(\'#courseS\').val() != 0)
            if(!($("#"+$(\'#courseS\').val()).length > 0))
            $(\'#course\').append("<tr id=\""+$(\'#courseS\').val()+"\"><input type=\"hidden\" name=\"courses[]\" value=\""+$(\'#courseS\').val()+"\" /><td>"+$(\'#courseS option:selected\').text()+"</td><td><button class=\"btn success removeCourse\" ><i class=\"icon-minus\"></i> Remover</button></td></tr>"); $(".removeCourse").click(function(e){ e.preventDefault(); $(this).parent().parent().remove();})');

    
    echo $this->Js->writeBuffer();
?>

